/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package config
import com.google.common.base.Strings;

import config.modules.Config;
import com.typesafe.config.ConfigBeanFactory;
import com.typesafe.config.ConfigFactory;

import java.io.File;
import java.nio.file.{Paths,Files}

object ConfigurationFactory {
    /**
     * Loads configuration object by file
     *
     * @return Returns configuration objects
     */
    def load():Config = {
        val stream = getClass.getResourceAsStream("/common.conf")
        if(null == stream){
            throw new RuntimeException("config file not exist")
        
        }

        val configresource
            = ConfigFactory.parseResources("common.conf");
        
        val topic = ConfigFactory.load(configresource).getString("producer.topic").replace("\"", "");;
        val hosts = ConfigFactory.load(configresource).getList("producer.hosts");
        val window = ConfigFactory.load(configresource).getString("producer.window");

        val config = new Config();
        println("..........hosts:"+hosts.toArray)
        for( entry <- hosts.toArray){
            println(entry)

            // config.producer=entry.asInstanceOf[String].replace("\"", "");
        }
        config.producer=hosts.toArray.mkString(",").replace("\"", "");
        println("..........hosts:"+config.producer)
        config.topic=topic;

        config
        // val conf=ConfigBeanFactory.create(config, classOf[Config]);

        
    }
}